package com.mzw.project.bizmq;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class BiMessageProducer {

    @Resource
    private RabbitTemplate rabbitTemplate;

    /**
     * 发送消息
     * @param message
     */
    public void sendMessage(String message) {
        rabbitTemplate.convertAndSend(BiMqConstant.API_EXCHANGE_NAME, BiMqConstant.API_ROUTING_KEY, message);
    }
    public void sendDelayedMessage(String message) {
//        long delay = 24 * 60 * 60 * 1000;
        long delay = 60 * 1000;
        rabbitTemplate.convertAndSend(BiMqConstant.DELAYED_EXCHANGE_NAME,
                BiMqConstant.DELAYED_ROUTING_KEY, message,  correlationData -> {
                    correlationData.getMessageProperties().setDelay((int) delay);
                    return correlationData;
                });
    }
}
